

package com.hazelcast.internal.partition.impl;


import com.hazelcast.internal.partition.MigrationInfo;

import java.util.Collection;
import java.util.EventListener;

/**
 * Internal synchronous/blocking listener to intercept migration cycle
 * on master member and migration participants.
 * <p>
 * It's used to execute a specific test scenario deterministically. There's no user side api or configuration.
 *
 * @see InternalPartitionServiceImpl#setMigrationInterceptor(MigrationInterceptor)
 */
public interface MigrationInterceptor extends EventListener {

    default void onMigrationStart(MigrationParticipant participant, MigrationInfo migration) {
    }

    default void onMigrationComplete(MigrationParticipant participant, MigrationInfo migration, boolean success) {
    }

    default void onMigrationCommit(MigrationParticipant participant, MigrationInfo migration) {
    }

    default void onMigrationRollback(MigrationParticipant participant, MigrationInfo migration) {
    }

    default void onPromotionStart(MigrationParticipant participant, Collection<MigrationInfo> migrations) {
    }

    default void onPromotionComplete(MigrationParticipant participant, Collection<MigrationInfo> migrations, boolean success) {
    }

    enum MigrationParticipant {
        MASTER, SOURCE, DESTINATION
    }

    class NopMigrationInterceptor implements MigrationInterceptor {
    }
}
